package ru.marketsoft.reminder.frames;

import ru.marketsoft.reminder.threads.Dump;
import ru.marketsoft.reminder.tools.Settings;
import ru.marketsoft.reminder.tools.Utils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.net.URI;

/**
 * User: dimka3210
 * Date: 28.02.13
 * Time: 20:52
 */
public class IFrame extends JFrame {
    private JPanel global;
    private JLabel label;
    private JLabel copyRight;

    public IFrame() throws HeadlessException {
        setTitle("Reminder");
        Dimension useFul = Utils.getUseFul(this);
        setIconImage(Toolkit.getDefaultToolkit().createImage("ru/marketsoft/reminder/icon.png"));
        setUndecorated(true);
        setAlwaysOnTop(true);
        setContentPane(global);
        setSize((int) useFul.getWidth(), 150);
        setLocation(0, (int) (useFul.getHeight() - 150));
        setIconImage(Utils.getIcon());

        Dump.setjLabel(label);

        label.setText(Settings.getInstance().getProperty("message"));
        label.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    Desktop.getDesktop().browse(new URI(Settings.getInstance().getProperty("report_site")));
                    setVisible(false);
                    Dump.stopColorOverFlow();
                    Dump.setNewRunnable(true);
                }
                catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });

        copyRight.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
        copyRight.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseExited(MouseEvent e) {
                copyRight.setForeground(new Color(255, 255, 255));
            }

            @Override
            public void mouseEntered(MouseEvent e) {
                copyRight.setForeground(new Color(255, 0, 0));
            }

            @Override
            public void mouseClicked(MouseEvent e) {
                try {
                    Desktop.getDesktop().browse(new URI("http://dimka3210.ru"));
                } catch (Exception e1) {
                    e1.printStackTrace();
                }
            }
        });

        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
        addWindowStateListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                SystemTray tray = SystemTray.getSystemTray();
                tray.remove(Dump.getTrayIcon());
                dispose();
            }
        });


    }
}
